﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Admin_ManageUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        gv_user.DataSource = Membership.GetAllUsers();
        gv_user.DataBind();
    }

    protected string GetRole(string[] _roles)
    {
        string _roleStr = string.Empty;
        foreach (var _r in _roles)
        {
            _roleStr += _r.ToString() + "<br/>";
        }
        return _roleStr;
    }
    protected void btn_Lock_Click(object sender, EventArgs e)
    {
        try
        {
            Button _btn = sender as Button;

            string _userName = string.IsNullOrEmpty(_btn.CommandArgument) ? string.Empty : _btn.CommandArgument;

            var _user = Membership.GetUser(_userName);
            if (_user != null)
            {
                if (Roles.IsUserInRole(_userName, "系统管理员")) throw new Exception("不能锁定系统管理员");

                if (_user.IsApproved == false || _user.IsLockedOut)
                {
                    _user.IsApproved = true;
                }
                else
                {
                    _user.IsApproved = false;
                }
                Membership.UpdateUser(_user);
            }
            gv_user.DataBind();
        }
        catch (Exception _e)
        {
            lbl_Error.Text = "错误:"+_e.Message;
        }
    }
}
